home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / Peon / PeonSDK-Win32-1.0.0.exe / {app} / PeonMain / include / SceneFont.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-11-25  |  3.9 KB  |  149 lines

  1.  
  2.  
  3. #ifndef __SCENEFONT_H_
  4. #define __SCENEFONT_H_
  5. /*
  6. Peon - Win32 Games Programming Library
  7. Copyright (C) 2002-2005 Erik Yuzwa
  8.  
  9. This library is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU Library General Public
  11. License as published by the Free Software Foundation; either
  12. version 2 of the License, or (at your option) any later version.
  13.  
  14. This library is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. Library General Public License for more details.
  18.  
  19. You should have received a copy of the GNU Library General Public
  20. License along with this library; if not, write to the Free
  21. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22.  
  23. Erik Yuzwa
  24. peon AT wazooinc DOT com
  25. */
  26.  
  27. #include "IUnknown.h"
  28.  
  29. namespace peon
  30. {
  31.     /**
  32.     * This object of the Peon library is meant to encapsulate a textured
  33.     * font object for your game. You provide it with a bitmap image
  34.     * of the alphabet you want to use (in ASCII format), then just notify
  35.     * this object of the dimensions of the bitmap. ie. how many rows
  36.     * and columns of characters there are, along with the pixel width 
  37.     * and height of a single character.
  38.     *
  39.     * This object is based off of the GLFont object made available by Jeff
  40.     * Molofee (aka. Nehe) at http://nehe.gamedev.net
  41.     */
  42.     class PEONMAIN_API SceneFont : public IUnknown
  43.     {
  44.  
  45.     protected:
  46.         /** display list to contain alphabet */
  47.         GLuint m_display_list;
  48.  
  49.         /** width of a single character */
  50.         int m_char_width;
  51.  
  52.         /** height of a single character */
  53.         int m_char_height;
  54.  
  55.         /** spacing between characters */
  56.         int m_char_spacing;
  57.  
  58.         /** how many characters in a line/row */
  59.         int m_fxCount;
  60.  
  61.         /** how many characters in a column */
  62.         int m_fyCount;
  63.  
  64.         /** the current red color when rendering our text*/
  65.         float m_r;
  66.  
  67.         /** the current green color when rendering our text*/
  68.         float m_g;
  69.  
  70.         /** the current blue color when rendering our text*/
  71.         float m_b;
  72.  
  73.         /** the current alpha color when rendering our text*/
  74.         float m_a;
  75.  
  76.         /** are we current batching text? */
  77.         bool m_font_batching; 
  78.  
  79.  
  80.     public:
  81.         /**
  82.         * Constructor
  83.         */
  84.         SceneFont();
  85.  
  86.         /**
  87.         * Destructor
  88.         */
  89.         ~SceneFont();
  90.  
  91.         /**
  92.         * This method is responsible for loading up our SceneFont
  93.         * instance.
  94.         * @param width - 
  95.         * @param height -
  96.         * @param spacing -
  97.         * @return bool - true if everything loaded properly
  98.         */
  99.         bool loadFont(int width = 16, int height = 16, int spacing = 14);
  100.  
  101.         /**
  102.         * This method is just used to unload our SceneFont instance
  103.         */
  104.         void unloadFont();
  105.  
  106.         /**
  107.         * This method is the "workhorse" which renders our text. We
  108.         * specify the x and y position of the text and that's where
  109.         * the SceneFont will render it!
  110.         * @param xpos - x position of text
  111.         * @param ypos - y position of text 
  112.         * @param strText - our text to render
  113.         * @return void
  114.         */
  115.         void renderText(float xpos, float ypos, const String& strText);
  116.  
  117.         /**
  118.         * This method just sets our color components in case we want
  119.         * to apply any color to the text we're about to render.
  120.         * @param r - red component
  121.         * @param g - green component
  122.         * @param b - blue component 
  123.         * @param a - alpha component
  124.         * @return void
  125.         */
  126.         void setColor( float r = 1.0f, float g = 1.0f, float b = 1.0f, float a = 1.0f);
  127.  
  128.         /**
  129.         * Sometimes we want to render batches of text to the screen...say like a 
  130.         * story, dialog text or whatever. To minimize the state changes, let's
  131.         * create a way for the the program to batch all the font rendering 
  132.         * commands THEN re-enable our original state/stacks..
  133.         * @return bool - are we ready to batch text?
  134.         */
  135.         bool beginBatchFont();
  136.  
  137.         /**
  138.         * We need to ensure we pair a beginBatchFont with an endBatchFont
  139.         */
  140.         void endBatchFont();
  141.         
  142.  
  143.     };
  144.  
  145. }
  146.  
  147. #endif
  148.  
  149.